#include "scr_state_game_over.h"
#include "scr_state_main_menu.h"
#include "scr_game_state_manager.h"
#include "scr_game.h"
#include "scr_font.h"
#include "scr_music.h"

SCRStateGameOver::SCRStateGameOver()
	: m_Timer(0)
	, m_Pressed(false)
{
}

SCRStateGameOver::~SCRStateGameOver()
{
}

void SCRStateGameOver::OnInitialize()
{
	m_Font = m_pGame->GetResourceManager()->GetFont("fonts/appleberry_with_cyrillic.ttf", 48);
}

void SCRStateGameOver::OnUpdate(const int& Delta)
{
	m_Timer += Delta;
}

void SCRStateGameOver::OnRender(const int& Delta)
{
	m_Font->Draw(SCRGame::SCR_SCREEN_WIDTH >> 1, SCRGame::SCR_SCREEN_HEIGHT >> 1,
		"GAME OVER", SCRFontType::SOLID, SCRFontAlign::CENTER_X | SCRFontAlign::CENTER_Y);
}

void SCRStateGameOver::OnKeyClick(const int& Key)
{
	if (!m_Pressed && m_Timer > 4000)
	{
		m_Pressed = true;
		m_pGame->GetStateManager()->SwitchTo<SCRStateMainMenu>();
		SCRMusicPtr Music = m_pGame->GetResourceManager()->GetMusic("music/intro.ogg");
		Music->Play();
	}	
}

void SCRStateGameOver::OnMouseClick(const int& X, const int& Y, const SCRMouseButton::Enum& Button)
{
	if (!m_Pressed && m_Timer > 4000)
	{
		m_Pressed = true;
		m_pGame->GetStateManager()->SwitchTo<SCRStateMainMenu>();
		SCRMusicPtr Music = m_pGame->GetResourceManager()->GetMusic("music/intro.ogg");
		Music->Play();
	}
}
